<?php
class Server {
  public static function delete_obj($orm, $sys, $inst, $is_iframe) {
    echo 'Disabled';
    return;
    $req = json_decode(Utils::get_param('req', '[]'));
    $orm->delete('pb_colg_student', $req);
    if (isset($req->__pg)) {
      $res = $orm->get('pb_colg_student', 't.id_number', 'DESC', $req->__pg, SIZE, NULL);
      echo json_encode($res);
    }
  }
  
  public static function get_objs($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    $res = $orm->get('pb_colg_student', $req->o, $req->q, $req->pg, SIZE, NULL);
    echo json_encode($res);
  }
  
  public static function autocomplete($orm, $sys, $inst, $is_iframe) {
    $req = Utils::get_param('term', '');
    
    $opts = new stdClass();
    $opts->cd = 't.title__ LIKE :v1';
    $opts->cdv = array(':v1' => '%' . $req . '%');
    $rslt = $orm->get('pb_colg_student', 't.title__', 'ASC', 1, SIZE, $opts)->d;
    $res = array();
    foreach ($rslt as $itm) {
      $obj = new stdClass();
      $obj->label = $itm->title__;
      $obj->value = $itm->title__;
      $obj->id = $itm->id;
      $res[] = $obj;
    }
    echo json_encode($res);
  }
  
  public static function search($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    
    $opts = new stdClass();
    $opts->cd = 't.title__ LIKE :v1';
    $opts->cdv = array(':v1' => '%' . $req->term . '%');
    $res = $orm->get('pb_colg_student', $req->o, $req->q, $req->pg, SIZE, $opts);
    echo json_encode($res);
  }
}
?>